package co.crossoft.exposeServiceImpl;

import co.crossoft.base.common.JsonResult;
import co.crossoft.daoImpl.TypeResourceDaoImpl;
import co.crossoft.domain.ResourceType;
import co.crossoft.service.ResourceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * Created by Snow on 8/24/2017.
 */
@Component
public class ResourceTypeServiceImpl implements ResourceTypeService {

    @Autowired
    TypeResourceDaoImpl typeResourceDao;

    /**
     * @param resourceTypeName 资源类型名称
     * @param description      描述
     * @param resourceAssList  分配资源到类型的List String类型放资源的handle
     * @return
     */
    @Override
    public JsonResult addOrUpdateResourceType(String resourceTypeName, String description, ArrayList<String> resourceAssList, String plant) {
        ResourceType resourceType = new ResourceType();
        resourceType.setHandle("RESOURCETYPE:" + plant + "," + resourceTypeName);
        resourceType.setDescription(description);
        resourceType.setResourceType(resourceTypeName);
        resourceType.setPlant(plant);
        return typeResourceDao.addOrUpdateResource(resourceType, resourceAssList);
    }

    /**
     * @param handle 资源类型handle 根据handle删除资源类型及其已分配到该类型下的资源对应关系
     * @return
     */
    @Override
    public JsonResult deleteResourceType(String handle) {
        return typeResourceDao.deleteResourceType(handle);
    }

    /**
     * @param resourceType 根据资源类型名称模糊查询资源类型
     * @return
     */
    @Override
    public JsonResult searchDataByResourceType(String resourceType) {

        return typeResourceDao.searchDataByResourceType(resourceType);
    }

    /**
     * @param handle
     * @return
     */
    @Override
    public JsonResult searchOneResourceTypeByHnadle(String handle) {
        return typeResourceDao.searchOneResourceTypeByHandle(handle);
    }
}
